<?php
class Web_View_Helper_HoraEntrega
	extends Zend_View_Helper_Abstract 
{

    public function horaEntrega( $negocio , $tipo ) 
	{
		$idNegocio = $negocio->getId();
	    
		$id = "fechaEntrega-{$idNegocio}-{$tipo}";
		$value = $this->view->rememberedOpcion( $id );
		
	    if ( ! $negocio->programado ){
	        $horariosHoy = $negocio->horariosDeliveryHoy();
	        
    	    $attribs = null;
    		
    		if(empty($horariosHoy)){
    			$horariosHoy[null] = $this->view->translate("sorryWeAreClosing");
    			$attribs = array('style' => 'width:210px;','disabled' => 'disabled');
    		}
    		
    		return $this->view->formSelect( $id, $value, $attribs, $horariosHoy);
	        
	    } else {
	    
	        $Zend_Date = new Zend_Date();
	        
	        $optionsDay = array();
	        $optionsHours = '';
	        
	        $horariosWeek = $negocio->horariosWeek( $tipo );
		
	        $n = 1;
	        
	        foreach ( $horariosWeek as $date=>$horarios ){
	        
	            $year = substr( $date,  0, 4);    
	            $month = substr( $date,  4, 2);    
	            $day = substr( $date,  6, 2);    
	            
	            
	            $Zend_Date->setYear($year);
	            $Zend_Date->setMonth($month);
	            $Zend_Date->setDay($day);
	            
	            if ( $Zend_Date->isToday() ){
	                $optionsDay[$date] = $this->view->translate('today');
	            }elseif( $Zend_Date->isTomorrow() ){
	                $optionsDay[$date] = $this->view->translate('tomorrow');
	            }else{
	                $optionsDay[$date] = ucfirst($Zend_Date->toString( Zend_Date::WEEKDAY . ' ' . Zend_Date::DAY));
	            }
	            
	            
	            //<option label="16:30 - 16:45" value="1316806200">16:30 - 16:45</option>
	            foreach ( $horarios as $time=>$horario ){
	                
	                $selected = $time == $value ? " selected='selected'" : null; 
	                
	                $optionsHours.="<option value='{$time}' date='{$date}'{$selected}>{$horario}</option>";
	            }
	            
	            $n++;
	        
	        }
	        
	        $id2 = "diaEntrega-{$idNegocio}-{$tipo}";
	        
	        $value2 = $this->view->rememberedOpcion( $id2 );
	        
	        return $this->view->formSelect( $id2, $value2, null, $optionsDay)
	                . "<select name='{$id}' id='{$id}'>{$optionsHours}</select>"; 
	        
	    }
	}
    
    
    
//	public function horaEntrega( $idNegocio, $horariosHoy = null, $tipo ) 
//	{
//		
//		$attribs = null;
//		
//		if(empty($horariosHoy)){
//			$horariosHoy[null] = $this->view->translate("sorryWeAreClosing");
//			$attribs = array('style' => 'width:210px;','disabled' => 'disabled');
//		}
//		
//		$id = "fechaEntrega-{$idNegocio}-{$tipo}";
//		$value = $this->view->rememberedOpcion( $id );
//		
//		return $this->formSelect( $id, $value, $attribs, $horariosHoy);
//	}
	
	
	

}